// Transformations.cpp: implementation of the Transformations class.
//
//////////////////////////////////////////////////////////////////////

#include "Transformations.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Transformations::Transformations()
{

}

Transformations::~Transformations()
{

}

//-------------- MATRIZ DE TRANSFORMACION TRANSLACION ----------------------------


void Transformations::setTranslationMatrix(double tx, double ty)
{

  	for (i = 0; i < N; i++)
	for (j = 0; j < N; j++)
	{
		if (i == j) {tt[i][j] = 1;}
		if (i != j) {tt[i][j] = 0;}

	}
	tt[0][2] = tx;
	tt[1][2] = ty;
}
//-------------- MATRIZ DE TRANSFORMACION ESCALADO ----------------------------

void Transformations::setScaleMatrix(double ex, double ey)
{

  	for (i = 0; i < N; i++)
	for (j = 0; j < N; j++)
	{
		if (i != j) {tt[i][j] = 0;}
	}
	tt[0][0] = ex;
	tt[1][1] = ey;
	tt[2][2] = 1;
}

void Transformations:: setRotationMatrix(double theta)    
{

	setScaleMatrix(cos(theta),cos(theta));
 	tt[0][1] = -sin(theta);
	tt[1][0] = sin(theta);

}


//------------------------------ metodos privados -----------------------------
void Transformations::setPoint(double x, double y)
{

  	p0[0] = x;
	p0[1] = y;
	p0[2] = 1;
}

void Transformations::initPoint()
{
    for (i = 0; i < N; i++) {p1[i] = 0;}

}

//-----------------------------------------------------------------------------


void Transformations::doTransformation(double x, double y, double * xt, double * yt)
{
    setPoint(x,y);
    initPoint();
    int i,j;
	for (i = 0; i < N; i++)
	for (j = 0; j < N; j++)
	{
		{p1[i] = (p1[i]  + (tt[i][j] * p0[j] ) );}
	}

   *xt = p1[0];
   *yt = p1[1];

}

